package com.yyplatform.admin.platform.file.controller;

import static com.yyplatform.admin.Constants.URL_PREFIX;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yyplatform.admin.infra.model.RestResponse;
import com.yyplatform.admin.platform.file.model.dto.SysFileConfigDTO;
import com.yyplatform.admin.platform.file.model.dto.SysFileConfigFormDTO;
import com.yyplatform.admin.platform.file.service.FileConfigService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * Created on 2024-09-18
 */
@Slf4j
@Tag(name = "文件/文件管理")
@AllArgsConstructor
@RestController
@RequestMapping(URL_PREFIX + "/sys/file/")
public class SysFileConfigController {


    private FileConfigService fileUploadService;


    @PostMapping("config/save")
    @Operation(summary = "保存文件上传配置")
    @RequiresPermissions("sys:file:saveConfig")
    public RestResponse<Void> saveConfig(@RequestBody SysFileConfigFormDTO sysFileConfigFormDTO) {
        log.debug("save file config dto is {}", sysFileConfigFormDTO);

        fileUploadService.saveConfig(sysFileConfigFormDTO);
        return RestResponse.ok();
    }


    @GetMapping("config/get")
    @Operation(summary = "获取文件上传配置")
    @RequiresPermissions("sys:file:getConfig")
    public RestResponse<SysFileConfigDTO> getConfig() {
        SysFileConfigDTO sysFileConfigDTO = fileUploadService.getConfig();

        return RestResponse.ok(sysFileConfigDTO);
    }

}
